package es.xpt.ysf.commons.business.view;

import java.util.Date;
import java.util.List;

import es.xpt.ysf.YSFException;
import es.xpt.ysf.commons.Names;
import es.xpt.ysf.commons.business.BusinessSession;
import es.xpt.ysf.commons.business.model.Currency;
import es.xpt.ysf.commons.business.model.CurrencyExchange;
import es.xpt.ysf.commons.business.model.Period;
import es.xpt.ysf.commons.business.model.Remark;
import es.xpt.ysf.view.LocalDelegate;
import es.xpt.ysf.view.model.UserBean;

public class BusinessDelegate extends LocalDelegate<BusinessSession>{

	public BusinessDelegate(UserBean user) {
		super(user);
	}
	
/********************************* REMARKS ***********************************/
	
	public List<Remark> getEntityRemarks(String entity, String entityID) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getEntityRemarks(entity, entityID);
	}
	
	public List<Remark> getEntityRemarks(String entity, String entityID, String locale) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getEntityRemarks(entity, entityID,locale);
	}
	
	public List<Remark> getEntityRemarksAllLanguages(String entity, String entityID) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getEntityRemarksAllLanguages(entity, entityID);
	}
	
	public List<Remark> getRemarkLanguages(String id) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getRemarkLanguages(id);
	}
	
	public void deleteRemark(String id, String locale) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.deleteRemark(id, locale);
	}
	
	public void deleteRemark(String id) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.deleteRemark(id);
	}
	
	public void insertRemark(Remark remark) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.insertRemark(remark);
	}
	
	public void insertRemarkLanguage(Remark remark) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.insertRemarkI18n(remark);
	}
	
	public void updateRemarkLanguage(Remark remark) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.updateRemarkI18n(remark);
	}
/********************************* PERIODS ***********************************/
	public List<Period> getEntityPeriods ( String entity, String entityID) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getEntityPeriods(entity, entityID);
	}

	public void deletePeriod(String id) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.deletePeriod(id);
	}

	public void insertPeriod(Period period) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.insertPeriod(period);
	}
	
	public void updatePeriod(Period period) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.updatePeriod(period);
	}
	
	/********************************* CURRENCY ***********************************/
	

	public List<CurrencyExchange> getExchangesByCurrencies(Currency source, Currency target) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getExchangesByCurrencies(source, target);
	}
	
	public List<CurrencyExchange> getAllExchanges() throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.getAllExchanges();
	}
	
	public void deleteExchanges(CurrencyExchange currencyExchange) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.deleteCurrencyExchange(currencyExchange);
	}
	
	public void insertExchange(CurrencyExchange currencyExchange) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.insertExchange(currencyExchange);
	}
	
	public void updateExchanges(CurrencyExchange currencyExchange, Date originalInitDate) throws YSFException {
		BusinessSession ejb = connect(Names.BUSINESS);
		ejb.updateExchange(currencyExchange,originalInitDate);
	}

	public List<String> deleteBatchCurrencyExchanges(List<CurrencyExchange> listCodeCurrencyExchange) throws YSFException{
		BusinessSession ejb = connect(Names.BUSINESS);
		return ejb.deleteBatchCurrencyExchanges(listCodeCurrencyExchange);
	}
}